let navUl = document.getElementsByClassName('nav-main')[0];
let nav = document.getElementsByClassName('nav')[0];
let navW = document.getElementsByClassName('nav-w')[0];
let subNav = document.getElementsByClassName('sub-nav');
let logo = document.getElementsByClassName('nav-content')[0].children[0];
let subNavArray = Array.from(subNav);
let scrollTop = document.documentElement.scrollTop || document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
let isHoverOnLink = false;
let lastScrollTop = 0;
isToW(false);
/* 监测页面距离顶部是否为0 */
window.onscroll = function() {
  isToW(false);
  isShowBackTop();
}
navUl.onmouseover = function() {
  changeNavW('toW',true)
}
navUl.onmouseout = function() {
  scrollTop = document.documentElement.scrollTop || document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
  scrollTop != 0 ? changeNavW('toW', false) : changeNavW('toNormal', false);
}
/* 改变二级导航栏的样式 */
function changeSubNav(n,isShow) {
  if(navW != undefined){
    isShow == true ? subNavArray[n].className = 'sub-nav active' : subNavArray[n].className = 'sub-nav';
  }else {
    changeNavW('toW', true);
    changeSubNav(n,isShow);
  }
}
/* 改变导航栏样式 */
function changeNavW(content,isHover) {
  isHoverOnLink = isHover;
  if(content == 'toW') {
    nav.className = 'nav-w';
    navW = document.getElementsByClassName('nav-w')[0];
    logo.src = 'img/menu_logo_hover.png';
    isHoverOnLink == true ? navW.style.height = '400px' : navW.style.height = '64.64px';
  }else {//toNormal
    if(isHoverOnLink == true){
      navW.style.height = '64.64px';
    }
    navW.className = 'nav';
    nav = document.getElementsByClassName('nav')[0];
    logo.src = 'img/menu_logo.png';
  }
}
/* 判断是否变成白色背景样式 */
function isToW(isHover) {
  scrollTop = document.documentElement.scrollTop || document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
  if(scrollTop != 0) {
    changeNavW('toW', isHover);
  }else {
    if(lastScrollTop != 0) {
      changeNavW('toNormal', isHover);
    }
  }
  if(scrollTop >= 100 && scrollTop - lastScrollTop > 0) {
    navW.style.top = '-65px';
  }else if(scrollTop - lastScrollTop < 0) {
    navW.style.top = '0';
  }
  lastScrollTop = scrollTop;
}